using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Diagnostics;


namespace BloodBot
{

    public class Player : Microsoft.Xna.Framework.GameComponent
    {
        public int totalHealth;
        public float currentHealth;
        float speed;
        Camera camera;
        public Vector3 pos;

        public Boolean losingHealth
        {
            get;
            private set;
        }

        public Stopwatch damageTimer;

        public Player(Game game, Camera camera)
            : base(game)
        {
            this.camera = camera;
            this.damageTimer = new Stopwatch();
        }

        public override void Initialize()
        {
            totalHealth = 100;
            currentHealth = totalHealth;


            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            pos = camera.cameraPosition;
            speed = camera.getSpeed();

            if (losingHealth)
            {
                if (damageTimer.Elapsed.Seconds > 2)
                {
                    this.losingHealth = false;
                    damageTimer.Reset();
                }
            }

            base.Update(gameTime);
        }

        public void adjustHealth(float adjustment)
        {
            // simply call this with a negative adjustment parameter to deal damage
            // call with a positive adjustment to give health
            if (losingHealth == false)
            {
                
                losingHealth = true;
                
            }
            damageTimer.Reset();
            damageTimer.Start();

            currentHealth += adjustment;
            currentHealth = MathHelper.Clamp(currentHealth, 0, totalHealth);
        }

        public bool Dead()
        {
            if (currentHealth == 0)
                return true;
            return false;
        }
    }
}
